<?php

/**
 * TEXY! USER IMAGES DEMO
 * --------------------------------------
 *
 * This demo shows how Texy! control images (useful for CMS)
 *     - programmable images controlling
 *     - onMouseOver state
 *     - support for preloading
 *
 * This source file is subject to the GNU GPL license.
 *
 * @link       http://www.texy.info/
 * @author     David Grudl aka -dgx- <dave@dgx.cz>
 * @copyright  Copyright (c) 2004-2006 David Grudl
 * @license    GNU GENERAL PUBLIC LICENSE
 */



// include Texy!
$texyPath = '../../texy/';
require_once ($texyPath . 'texy.php');



// this is user callback function for processing 'image references' [*xxxx*]
// returns FALSE or TexyImageReference

function &myUserFunc($refName, &$texy) {
    if ($refName != '*user*') { // accept only [* user *]
        $FALSE = FALSE; // php4_sucks
        return $FALSE;
    }

    $elRef = &new TexyImageReference($texy);
    $elRef->URLs = 'image.gif | '        // image URL
                 . 'image-over.gif | '   // onmouseover image
                 . 'big.gif';          // linked image
    $elRef->modifier->title = 'Texy! logo';
    return $elRef;
}



$texy = &new Texy();
$texy->referenceHandler        = 'myUserFunc';       // callback
$texy->imageModule->root       = 'imagesdir/';       // "in-line" images root
$texy->imageModule->linkedRoot = 'imagesdir/big/';   // "linked" images root
$texy->imageModule->leftClass  = 'my-left-class';    // left-floated image modifier
$texy->imageModule->rightClass = 'my-right-class';   // right-floated image modifier
$texy->imageModule->defaultAlt = 'default alt. text';// default image alternative text


// processing
$text = file_get_contents('sample.texy');
$html = $texy->process($text);  // that's all folks!


// echo formated output
echo $html;



// echo generated HTML code
echo '<hr />';
echo '<pre>';
echo htmlSpecialChars($html);
echo '</pre>';



// echo all used images
echo '<hr />';
echo '<pre>';
echo 'used images:';
print_r($texy->summary->images);
echo 'onmouseover images:';
print_r($texy->summary->preload);
echo '</pre>';




// build preload script!
$script = "var preloadImg = new Array();\n";
foreach ($texy->summary->preload as $key => $image)
    $script .= "preloadImg[$key] = new Image(); preloadImg[$key].src='".htmlSpecialChars($image, ENT_QUOTES)."';\n";

echo '<pre>';
echo $script;
echo '</pre>';


?>